"""
@文件: Response.py
@Author: ZJJ
@Email: 1065377805@qq.com
@Time: 2025/3/7
@Des:数据响应文件
"""
from typing import List, Optional, Any


def res_ajax(data: Optional[List[Any]] = None, total: int = 0, code: bool = True):
    """
    支持ant-design-table 返回的格式
    :param code:
    :param data:
    :param total:
    :return:
    """
    if data is None:
        data = []
    result = {
        "success": code,
        "data": data,
        "total": total
    }
    return result


def base_response(code, msg, data=None):
    """基础返回格式"""
    if data is None:
        data = []
    result = {
        "success": code,
        "message": msg,
        "data": data
    }
    return result


def success(data=None, msg='',code: bool = True):
    """成功返回格式"""
    return base_response(code, msg, data)


def fail(code=-1, msg='', data=None):
    """失败返回格式"""
    return base_response(code, msg, data)